﻿///<reference path="../../../Scripts/jquery-1.4.1-vsdoc.js"/>
///<reference path="../utils/Utils.js"/>

// книга Библии
function BibleBook(key, title, chaptersCount) {

    this.Title = title;
    this.Key = key;
    this.ChaptersCount = chaptersCount;
    this.Chapters = [];
    this.Xml;

    this.AddChapter = function (key, title) {
        return this.GetChapter[this.Chapters.push(new BibleChapter(key, title)) - 1];
    }

    this.GetChapterByIndex = function (index) {
        return this.Chapters[index];
    }

    this.GetChapter = function (chapterKey) {
        var chapterIndex = appPointer.KeyManager.GetChapterIndexFromKey(chapterKey);
        return this.GetChapterByIndex(chapterIndex); 
    }

    this.Search = function (searchPattern) {
        var results = [];
        for (var i = 0; i < this.Chapters.length; i++) {
            var chapter = this.GetChapterByIndex(i);
            AddRange(results, chapter.Search(searchPattern));            
        }
        return results;
    }

    this.EachChapter = function (callback) {
        for (var i = 0; i < this.Chapters.length; i++) {
            callback.call(this.Chapters[i], i);
        }
    }
}